//
//  PopElementItem.m
//  EpointFrame5
//
//  Created by Pill Gong on 14-4-16.
//  Copyright (c) 2014年 Epoint. All rights reserved.
//

#import "PopElementItem.h"

@interface PopElementItem ()

@property (nonatomic, strong) UIButton *itemButton;

@end

@implementation PopElementItem {
    UIColor *normalColor;
    UIColor *highlightColor;
}

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setDefaultValues];
        [self addItemButton];
    }
    return self;
}

- (void)setDefaultValues {
    normalColor = [UIColor whiteColor];
    highlightColor = COLOR(249, 247, 84);
}

- (void)addItemButton {
    self.itemButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _itemButton.frame = self.bounds;
    _itemButton.backgroundColor = [UIColor clearColor];
    _itemButton.titleLabel.font = [UIFont boldSystemFontOfSize:17.0];
    [_itemButton setTitleColor:normalColor forState:UIControlStateNormal];
    [_itemButton setTitleColor:highlightColor forState:UIControlStateHighlighted];
    [_itemButton setTitleColor:highlightColor forState:UIControlStateSelected];
    [_itemButton addTarget:self action:@selector(itemButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_itemButton];
}

- (void)itemButtonPressed:(id)sender {
    if (_delegate && [_delegate respondsToSelector:@selector(popElementItemDidSelected:)]) {
        [_delegate popElementItemDidSelected:self];
    }
}

#pragma mark - property

- (void)setTitle:(NSString *)title {
    [_itemButton setTitle:title forState:UIControlStateNormal];
}

- (void)setIsSelected:(BOOL)isSelected {
    _isSelected = isSelected;
    [_itemButton setSelected:_isSelected];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
